package org.javaboy.demo;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.indices.CreateIndexResponse;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;

import java.io.IOException;

public class Client01 {
    public static void main(String[] args) throws IOException {
        RestClient client = RestClient.builder(new HttpHost("localhost", 9200, "http")).build();
        RestClientTransport transport = new RestClientTransport(client, new JacksonJsonpMapper());
        ElasticsearchClient es = new ElasticsearchClient(transport);
        CreateIndexResponse test02 = es.indices().create(f -> f.index("test02").settings(s -> s.numberOfReplicas("1").numberOfShards("1")));
        System.out.println("test02.index() = " + test02.index());
        System.out.println("test02.acknowledged() = " + test02.acknowledged());
        System.out.println("test02.shardsAcknowledged() = " + test02.shardsAcknowledged());
    }
}
